// component/common/collapseTag/collapseTag.js
Component({
  /**
   * 组件的配置
   */
  options: {
    styleIsolation: 'isolated',
    pureDataPattern: /^_/,
  },
  /**
   * 组件的属性列表
   */
  properties: {
    title: {
      type: String,
      value: '',
    },
    list: {
      type: Array,
      value: [],
    },
    current: {
      type: Array,
      value: [],
    },
    column: {
      type: String,
      value: '4',
    },
    key: {
      type: String,
      value: 'label',
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    isExpand: false,
    totalHeight: 0,
  },

  /**
   * 组件的数据监听
   */
  observers: {
    isExpand(isExpand) {
      let row = 0
      if (isExpand) {
        row = Math.ceil(this.data.list.length / this.data.column)
      }
      this.setData({
        totalHeight: row * 76
      })
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onFold() {
      this.setData({
        isExpand: !this.data.isExpand
      })
    },

    onClick(e) {
      this.triggerEvent('active', e.currentTarget.dataset.item)
    }
  }
})